<template>
  <el-dialog title="新增" width="450px"
             :close-on-click-modal="false"
             :close-on-press-escape="false"
             :visible.sync="dialogVisible"
             :before-close="handleClose" >
    <el-form ref="form" :model="form" :rules="rules" label-width="80px" class="tams-form-container">
      <el-form-item label="班级编号" prop="classId">
        <el-input v-model="form.classId" class="tams-form-item"></el-input>
      </el-form-item>
      <el-form-item label="班级名称" prop="className">
        <el-input v-model="form.className" class="tams-form-item"></el-input>
      </el-form-item>
      <el-form-item label="座位数" prop="classCount">
        <el-input v-model="form.classCount" class="tams-form-item"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取消</el-button>
      <el-button type="primary" :loading="submitBtnLoading" @click="submit(form)">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { mapActions } from 'vuex'
import Qs from 'qs'
export default {
  name: 'SaveClass',
  props: {
    visible: {
      type: Boolean
    }
  },
  data () {
    return {
      dialogVisible: false,
      form: {},
      rules: {
        name: [
          {
            required: true,
            message: '名称不能为空',
            trigger: 'blur'
          }
        ]
      },
      submitBtnLoading: false
    }
  },
  methods: {
    ...mapActions(['SaveClass']),
    handleClose (done) {
      this.$refs.form.resetFields()
      this.$emit('on-close')
      done()
    },
    close () {
      this.$refs.form.resetFields()
      this.$emit('on-close')
      this.dialogVisible = false
    },
    submit (form) {
      console.log(form)
      // this.$axios.post('http://localhost:8080/classExcel/addClasses',
      // JSON.stringify({data:this.form}),{headers:{'Content-Type':'application/json'}}).then(res => {
      // })

      this.$axios({
        url:'http://localhost:8080/classExcel/addClasses',
        method:'post',
        data:JSON.stringify(form),
        headers:{
          'Content-Type':'application/json'
        }
      })
      this.$router.go(0)
      this.dialogVisible=false
    }
  },
  watch: {
    visible (val) {
      if (val) {
        this.dialogVisible = val
      }
    }
  }
}
</script>
